import axios from '@/utils/axios.js'

// 获取权限
export const getRoles = () =>
  axios({
    method: 'GET',
    url: 'roles'
  })

// 删除角色
export const deleteRolesById = roleId =>
  axios({
    method: 'DELETE',
    url: `roles/${roleId}`
  })

//  //roles/${role.id}/rights/${rightId}
// 删除角色指定权限
export const deleteRolesRightsById = (roleId, rightId) =>
  axios({
    method: 'DELETE',
    url: `roles/${roleId}/rights/${rightId}`
  })

// 角色新增
export const addRole = data =>
  axios({
    method: 'POST',
    url: 'roles',
    data
  })

// roles/:id
// 角色编辑
export const editRoleByID = data =>
  axios({
    method: 'PUT',
    url: `roles/${data.roleId}`,
    data
  })

// roles/:roleId/rights
// 角色授权
export const setRoleRights = data =>
  axios({
    method: 'POST',
    url: `roles/${data.roleId}/rights`,
    data
  })

// users/:id/role
// 给用户分配角色 ==> 参数id:uid,rid:角色id
export const setUserRole = data =>
  axios({
    method: 'PUT',
    url: `users/${data.id}/role`,
    data
  })
